package com.ymatou.iapi.trading.sellerquery2.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.po.OrderInfoSubPo;
import com.ymatou.iapi.trading.ordersync.service.SyncVerifyService;
import com.ymatou.iapi.trading.sellerquery2.parameter.vo.SubProductInfo;
import com.ymatou.query.seller.trading.api.parameter.ExportSellerProductInfosResponse;
import com.ymatou.query.seller.trading.api.parameter.GetExportProductInfoResult;
import com.ymatou.query.seller.trading.api.parameter.SellerExportedProductInfo;
import com.ymatou.query.seller.trading.api.parameter.Ymt_O_OrderNote;
import com.ymatou.query.seller.trading.api.parameter.Ymt_Order;
import com.ymatou.query.seller.trading.api.parameter.Ymt_OrderInfo;
import com.ymatou.query.seller.trading.api.parameter.Ymt_OrderState;
import com.ymatou.query.seller.trading.api.service.OrderCreate;
import com.ymatou.query.trading.api.parameter.GetExportProductInfo;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.entitie.C2COrderInfo.C2COrderInfoExt;
import com.ymttest.common.enums.LogisticsTypeEnum;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.common.order.sellerquery2.Convertor;
import com.ymttest.common.order.sellerquery2.ExportOrderInfo;
import com.ymttest.common.order.sellerquery2.TimeRange;
import com.ymttest.common.order.sellerquery2.bean.ExportSellerProductInfosBean;
import com.ymttest.common.order.sellerquery2.model.SellerExportOrderQueryModel;
import com.ymttest.common.order.sellerquery2.sp.Sp_GetExportProductInfoByOrderIds_v1;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * @date 2016-06-28
 * @author songyefeng
 * @desc 分批导出卖家订单信息
 */
@TestSuite
public class Ts_ExportSellerProductInfos {

	private static ExportSellerProductInfosBean request;
	//	private static com.ymatou.query.seller.trading.api.service.ExportSellerProductInfosCall call;
	private static com.ymatou.iapi.trading.sellerquery2.service.ExportSellerProductInfosCall call;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("分批导出卖家订单信息");
	}

	@Before
	public void caseUp() {
		request = new ExportSellerProductInfosBean();
		//		call = new com.ymatou.query.seller.trading.api.service.ExportSellerProductInfosCall();
		call = new com.ymatou.iapi.trading.sellerquery2.service.ExportSellerProductInfosCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() {
		ExportSellerProductInfosResponse expectedResponse = new ExportSellerProductInfosResponse();
		ConstructResponse(expectedResponse);
		ExportSellerProductInfosResponse actualResponse = call
				.getExportSellerProductInfosResponse();
		DataUtil.verify(expectedResponse.getNextPartitionKey(),
				actualResponse.getNextPartitionKey(), "验证NextPartitionKey");
		List<SellerExportedProductInfo> expects = expectedResponse
				.getSellerExportedPartialProductInfos();
		List<SellerExportedProductInfo> actuals = actualResponse
				.getSellerExportedPartialProductInfos();
		if (DataUtil.isNullOrEmpty(expects)) {
			DataUtil.verify(
					true,
					DataUtil.isNullOrEmpty(actuals),
					"验证SellerExportedPartialProductInfos == null 或者 SellerExportedPartialProductInfos为空列表");
		} else {
			boolean notnull = !DataUtil.isNullOrEmpty(actuals);
			DataUtil.verify(
					true,
					notnull,
					"验证SellerExportedPartialProductInfos != null 且 SellerExportedPartialProductInfos不是空列表");
			if (notnull) {
				boolean sameSize = expects.size() == actuals.size();
				DataUtil.verify(expects.size(), actuals.size(),
						"验证SellerExportedPartialProductInfos.size()");
				if (sameSize) {
					net.sf.json.JSONArray exps = net.sf.json.JSONArray
							.fromObject(expects);
					net.sf.json.JSONArray acts = net.sf.json.JSONArray
							.fromObject(actuals);
					exps = DataUtil.Json.parseJsonArray(DataUtil.Json
							.sortJsonArray(exps));
					acts = DataUtil.Json.parseJsonArray(DataUtil.Json
							.sortJsonArray(acts));
					List<SellerExportedProductInfo> sortedExpects = new ArrayList<SellerExportedProductInfo>();
					List<SellerExportedProductInfo> sortedActuals = new ArrayList<SellerExportedProductInfo>();
					for (int i = 0; i < exps.size(); i++) {

						SellerExportedProductInfo expect = (SellerExportedProductInfo) FormatUtil
								.GSONToObject(exps.get(i).toString(),
										SellerExportedProductInfo.class);
						SellerExportedProductInfo actual = (SellerExportedProductInfo) FormatUtil
								.GSONToObject(acts.get(i).toString(),
										SellerExportedProductInfo.class);

						sortedExpects.add(expect);
						sortedActuals.add(actual);
					}

					expects.sort((a, b) -> a.getOrderNo() - b.getOrderNo());
					expects.sort((a, b) -> a.getAddTime().compareTo(
							b.getAddTime()));
					verifyProductInfos(sortedExpects, sortedActuals);
				}
			}
		}

	}

	private void verifyProductInfos(List<SellerExportedProductInfo> expects,
			List<SellerExportedProductInfo> actuals) {

		for (int i = 0; i < expects.size(); i++) {

			SellerExportedProductInfo expect = expects.get(i);
			SellerExportedProductInfo actual = actuals.get(i);

			int index = i + 1;
			Logger.comment("开始验证第 " + index + " 条记录");
			DataUtil.verify(expect.getOrderNo(), actual.getOrderNo(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的OrderNo");
			DataUtil.verify(expect.getProductNos(), actual.getProductNos(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的ProductNos");
			DataUtil.verify(expect.getProductNames(), actual.getProductNames(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的ProductNames");
			DataUtil.verify(expect.getCatalogInfos(), actual.getCatalogInfos(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的CatalogInfos");
			DataUtil.verify(expect.getProductNum(), actual.getProductNum(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的ProductNum");
			DataUtil.verify(expect.getProductPrice(), actual.getProductPrice(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的ProductPrice");
			DataUtil.verify(expect.getFreight(), actual.getFreight(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的Freight");
			DataUtil.verify(expect.getDepositAmount(),
					actual.getDepositAmount(), "验证第 " + index
							+ " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的DepositAmount");
			DataUtil.verify(expect.getPostPayAmount(),
					actual.getPostPayAmount(), "验证第 " + index
							+ " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的PostPayAmount");
			DataUtil.verify(expect.getCashAmount(), actual.getCashAmount(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的CashAmount");
			DataUtil.verify(expect.getTotalAmount(), actual.getTotalAmount(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的TotalAmount");
			//			DataUtil.verify(expect.getOrderType(), actual.getOrderType(),"验证第 "+ index +" 条记录的OrderType");
			DataUtil.verify(expect.getOrderState(), actual.getOrderState(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的OrderState");
			DataUtil.verify(expect.getAddTime(), actual.getAddTime(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的AddTime");
			DataUtil.verify(expect.getPayTime(), actual.getPayTime(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的PayTime");
			DataUtil.verify(expect.getLeaveWord(), actual.getLeaveWord(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的LeaveWord");
			DataUtil.verify(expect.getBuyerLoginId(), actual.getBuyerLoginId(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的BuyerLoginId");
			DataUtil.verify(expect.getReceivePerson(),
					actual.getReceivePerson(), "验证第 " + index
							+ " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的ReceivePerson");
			DataUtil.verify(expect.getPhone(), actual.getPhone(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的Phone");
			DataUtil.verify(expect.getTelephone(), actual.getTelephone(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的Telephone");
			DataUtil.verify(expect.getAddress(), actual.getAddress(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的Address");
			DataUtil.verify(expect.getPostCode(), actual.getPostCode(), "验证第 "
					+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
					+ "],实际orderNo=[" + actual.getOrderNo() + "]的PostCode");
			DataUtil.verify(expect.getRefundAmount(), actual.getRefundAmount(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的RefundAmount");
			DataUtil.verify(expect.getOrderNote(), actual.getOrderNote(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的OrderNote");
			DataUtil.verify(expect.getPackageDelivery_DomesticDelivered(),
					actual.getPackageDelivery_DomesticDelivered(), "验证第 "
							+ index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的PackageDelivery_DomesticDelivered");
			DataUtil.verify(expect.getRemarkLevel(), actual.getRemarkLevel(),
					"验证第 " + index + " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的RemarkLevel");
			//			DataUtil.verify(expect.getRiskVerifiedStatus(), actual.getRiskVerifiedStatus(),"验证第 "+ index +" 条记录, 期望orderNo=["+expect.getOrderNo()+"],实际orderNo=["+actual.getOrderNo()+"]的RiskVerifiedStatus");
			DataUtil.verify(expect.getSellerCouponAmount(),
					actual.getSellerCouponAmount(), "验证第 " + index
							+ " 条记录, 期望orderNo=[" + expect.getOrderNo()
							+ "],实际orderNo=[" + actual.getOrderNo()
							+ "]的SellerCouponAmount");

			//校验组合商品
			verifySubProducts(expect.getOrderNo(), actual);
		}
	}
	/**
	 * 校验组合商品
	 * @param expectId
	 * @param actProducts
	 */
	private static void verifySubProducts(int expectId,

	SellerExportedProductInfo actProduct) {

		DefaultWapper data = new DefaultWapper();

		int orderId = actProduct.getOrderNo();

		try {

			List<SubProductInfo> actualOrderInfoSub = actProduct
					.getSubProductInfos();

			if (!CollectionUtils.isEmpty(actualOrderInfoSub)) {

				Logger.comment("验证id=[" + orderId + "]Products 下组合商品记录数");

				List<OrderInfoSubPo> orderInfoSubPoList = data.getOrderInfoSub(
						actProduct.getOrderNo(), actualOrderInfoSub.get(0)
								.getCatalogId());

				for (int i = 0; i < actualOrderInfoSub.size(); i++) {

					SubProductInfo actual = actualOrderInfoSub.get(i);

					OrderInfoSubPo expect = orderInfoSubPoList.get(i);

					Logger.comment("开始验证catalogId=[" + actual.getCatalogId()
							+ "]的Products下的组合商品");

					Logger.verifyEquals(expect.getSubTitle(),
							actual.getSubTitle(), "校验组合商品 subTitle");
					Logger.verifyEquals(expect.getSubCatalogId(),
							actual.getSubCatalogId(), "校验组合商品 subCatalogId");
					Logger.verifyEquals(expect.getFirstCatId(),
							actual.getFirstCatId(), "校验组合商品 firstCatId");

					Logger.verifyEquals(expect.getSecondCatId(),
							actual.getSecondCatId(), "校验组合商品 secondCatId");

					Logger.verifyEquals(expect.getThirdCatId(),
							actual.getThirdCatId(), "校验组合商品 thirdCatId");

					Logger.verifyEquals(expect.getNum(), actual.getNum(),
							"校验组合商品 num");

					DataUtil.verifyDecimalEquals(expect.getOriginalPrice(),
							actual.getOriginalPrice(), "校验组合商品 originalPrice");

					DataUtil.verifyDecimalEquals(expect.getPrice(),
							actual.getPrice(), "校验组合商品 price");

					DataUtil.verifyDecimalEquals(expect.getFreight(),
							actual.getFreight(), "校验组合商品 freight");

					DataUtil.verifyDecimalEquals(expect.getDiscount(),
							actual.getDiscount(), "校验组合商品 discount");

					DataUtil.verifyDecimalEquals(expect.getYmtCoupon(),
							actual.getYmtCoupon(), "校验组合商品 ymtCoupon");

					DataUtil.verifyDecimalEquals(expect.getSellerCoupon(),
							actual.getSellerCoupon(), "校验组合商品 sellerCoupon");

					DataUtil.verifyDecimalEquals(
							expect.getThirdPartyDiscount(),
							actual.getThirdPartyDiscount(),
							"校验组合商品 thirdPartyDiscount");

					DataUtil.verifyDecimalEquals(expect.getPromotion(),
							actual.getPromotion(), "校验组合商品 promotion");

				}

			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	private void ConstructResponse(ExportSellerProductInfosResponse response) {
		Process(response);
	}

	private void Process(ExportSellerProductInfosResponse response) {
		SellerExportOrderQueryModel model = Convertor
				.SellerExportOrderRequestArguments(request);
		ExportSellerProductInfosResponseProcessor(model, response);
	}

	@SuppressWarnings("rawtypes")
	private void ExportSellerProductInfosResponseProcessor(
			SellerExportOrderQueryModel model,
			ExportSellerProductInfosResponse response) {
		Sp_GetExportProductInfoByOrderIds_v1 sp = ExportOrderInfo
				.GetExportSellerProductInfoListSqlCommand(model);
		List<Map> orders = sp.getOrders();
		List<Map> orderInfos = sp.getOrderInfos();
		List<Map> orderNotes = sp.getOrderNotes();
		List<Map> orderStates = sp.getOrderStates();
		GetExportProductInfoResult result = ConvertResult(orders, orderInfos,
				orderNotes, orderStates);
		if (DataUtil.isNullOrEmpty(result.getOrders())) {
			response.setSellerExportedPartialProductInfos(new ArrayList<SellerExportedProductInfo>());
			response.setNextPartitionKey(null);
		}
		response.setNextPartitionKey(result.getOrders().size() < ExportOrderInfo.MAX_PER_QUERY_COUNT
				? null
				: String.valueOf(result.getOrders().stream()
						.min((a, b) -> a.getiOrderId() - b.getiOrderId()).get()
						.getiOrderId()));
		response.setSellerExportedPartialProductInfos(GetExportProductInfo
				.GetExportProductInfos(result));
	}

	@SuppressWarnings("rawtypes")
	private GetExportProductInfoResult ConvertResult(List<Map> orders,
			List<Map> orderInfos, List<Map> orderNotes, List<Map> orderStates) {
		GetExportProductInfoResult result = new GetExportProductInfoResult();
		List<Ymt_Order> Orders = new ArrayList<Ymt_Order>();
		List<Ymt_OrderInfo> OrderInfos = new ArrayList<Ymt_OrderInfo>();
		List<Ymt_O_OrderNote> OrderNotes = new ArrayList<Ymt_O_OrderNote>();
		List<Ymt_OrderState> OrderStates = new ArrayList<Ymt_OrderState>();
		if (false == DataUtil.isNullOrEmpty(orders)) {
			for (Map m : orders) {
				Ymt_Order order = new Ymt_Order();
				DataUtil.mapToBean(order, m);
				Orders.add(order);
			}
		}
		if (false == DataUtil.isNullOrEmpty(orderInfos)) {
			for (Map m : orderInfos) {
				Ymt_OrderInfo oi = new Ymt_OrderInfo();
				DataUtil.mapToBean(oi, m);
				OrderInfos.add(oi);
			}
		}
		if (false == DataUtil.isNullOrEmpty(orderNotes)) {
			for (Map m : orderNotes) {
				Ymt_O_OrderNote note = new Ymt_O_OrderNote();
				DataUtil.mapToBean(note, m);
				OrderNotes.add(note);
			}
		}
		if (false == DataUtil.isNullOrEmpty(orderStates)) {
			for (Map m : orderStates) {
				Ymt_OrderState state = new Ymt_OrderState();
				DataUtil.mapToBean(state, m);
				OrderStates.add(state);
			}
		}
		result.setOrders(Orders);
		result.setOrderInfos(OrderInfos);
		result.setOrderNotes(OrderNotes);
		result.setOrderStates(OrderStates);
		return result;
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_001() {
		Logger.start(true, "分批导出卖家订单信息");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_002() {
		Logger.start(true, "分批导出卖家订单信息, 测试paidTime筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_003() {
		Logger.start(true, "分批导出卖家订单信息, 测试订单状态为17的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.SellerAccept.getValue());
			request.setOrderStatus(orderStatus);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_004() {
		Logger.start(true, "分批导出卖家订单信息, paidTime的end为空");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_005() {
		Logger.start(true, "分批导出卖家订单信息, paidTime的start为空");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-2,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			request.setOrderId(112501608);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}

	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_007() {
		Logger.start(true, "分批导出卖家订单信息, 测试BuyerNickName的筛选(es)");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			String buyerNickName = String.valueOf(EnvSetup
					.getData("BuyUserName"));
			TimeRange createTime = new TimeRange();
			createTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-7,
					YMTDateUtil.YMDTHMS_STRING));
			createTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createTime);
			request.setSellerId(SellerId);
			request.setBuyerNickName(buyerNickName);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_008() {
		Logger.start(true, "分批导出卖家订单信息, 测试CreatedTime的筛选,begin+end");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-20,
					YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_009() {
		Logger.start(true, "分批导出卖家订单信息, 测试CreatedTime的筛选,只有begin");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_010() {
		Logger.start(true, "分批导出卖家订单信息, 测试CreatedTime的筛选,只有end");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange createdTime = new TimeRange();
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_011() {
		Logger.start(true, "分批导出卖家订单信息, 测试DeliveredTime的筛选,begin+end");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange deliveredTime = new TimeRange();
			deliveredTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-5,
					YMTDateUtil.YMDTHMS_STRING));
			deliveredTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-3,
					YMTDateUtil.YMDTHMS_STRING));
			request.setDeliveredTime(deliveredTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_012() {
		Logger.start(true, "分批导出卖家订单信息, 测试DeliveredTime的筛选,只有begin");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange deliveredTime = new TimeRange();
			deliveredTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			request.setDeliveredTime(deliveredTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_013() {
		Logger.start(true, "分批导出卖家订单信息, 测试DeliveredTime的筛选,只有end");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange deliveredTime = new TimeRange();
			deliveredTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-30,
					YMTDateUtil.YMDTHMS_STRING));
			request.setDeliveredTime(deliveredTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_ExportSellerProductInfos_014() {
		Logger.start(true, "分批导出卖家订单信息, 测试LogisticsTypes的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes
					.add(LogisticsTypeEnum.XloboBondedDelivery.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-5,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_015() {
		Logger.start(true, "分批导出卖家订单信息, 导出下单状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create1_M2cOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_016() {
		Logger.start(true, "分批导出卖家订单信息, 测试OrderStatus的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatus.add(OrderStatusEnum.OrderEstablish.getValue());
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-5,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_017() {
		Logger.start(true, "分批导出卖家订单信息,测试partitionKey");
		try {
			Logger.comment("准备测试数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			String partitionKey = String.valueOf(o.create1_M2cOrder(userId,
					sellerId).getiOrderId());
			for (int i = 0; i < 3; i++) {
				o.create1_M2cOrder(userId, sellerId);
			}
			Thread.sleep(5000l);
			Logger.comment("完成准备测试数据");
			request.setSellerId(sellerId);
			TimeRange time = new TimeRange();
			time.setBegin(YMTDateUtil.getBeforeOrNextDay(-7,
					YMTDateUtil.YMDTHMS_STRING));
			time.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(time);
			call.setData(request);
			call.callService();
			request.setPartitionKey(partitionKey);
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_018() {
		Logger.start(true, "分批导出卖家订单信息, 导出支付状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create2_PayOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_019() {
		Logger.start(true, "分批导出卖家订单信息, 导出发货状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create3_ShippedOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_020() {
		Logger.start(true, "分批导出卖家订单信息, 导出收货状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create4_ReceivedOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_021() {
		Logger.start(true, "分批导出卖家订单信息, 测试ProductName的筛选(es)");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			Logger.comment("准备测试数据");
			String productName = new OrderCreate().create1_M2cOrder(userId,
					sellerId).getsTitle();
			Thread.sleep(3000l);
			Logger.comment("完成准备测试数据");
			TimeRange time = new TimeRange();
			time.setBegin(YMTDateUtil.getBeforeOrNextDay(-10,
					YMTDateUtil.YMDTHMS_STRING));
			time.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(time);
			request.setSellerId(sellerId);
			request.setProductName(productName);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_022() {
		Logger.start(true, "分批导出卖家订单信息, orderstatus=1,2,17,3,4");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatus.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatus.add(OrderStatusEnum.SellerAccept.getValue());
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			orderStatus.add(OrderStatusEnum.Received.getValue());
			request.setOrderStatus(orderStatus);
			TimeRange time = new TimeRange();
			time.setBegin(YMTDateUtil.getBeforeOrNextDay(-7,
					YMTDateUtil.YMDTHMS_STRING));
			time.setEnd(YMTDateUtil.getBeforeOrNextDay(0,
					YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(time);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_023() {
		Logger.start(true, "分批导出卖家订单信息, 导出收货后退货退款成功状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create4_RefundOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_024() {
		Logger.start(true, "分批导出卖家订单信息, 导出收货后申请退货退款状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o
					.create4_ApplyRefundOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_025() {
		Logger.start(true, "分批导出卖家订单信息, 导出收货后退货退款失败状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create4_RefundFailedOrder(userId,
					sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_026() {
		Logger.start(true, "分批导出卖家订单信息, 导出买手接单状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create17_RefundOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_027() {
		Logger.start(true, "分批导出卖家订单信息, 导出买手接单后退货退款成功状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create17_RefundOrder(userId, sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_028() {
		Logger.start(true, "分批导出卖家订单信息, 导出买手接单后申请退货退款状态的订单(orderid筛选)");
		try {
			Logger.comment("准备订单数据");
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			OrderCreate o = new OrderCreate();
			C2COrderInfoExt order = o.create17_ApplyRefundOrder(userId,
					sellerId);
			// Thread.sleep(2000);
			Logger.comment("完成准备订单数据");
			if (SyncVerifyService.getSyncResult(order.getiOrderId())) {
				request.setSellerId(sellerId);
				request.setOrderId(order.getiOrderId());
				call.setData(request);
				call.callService();
				Logger.verifyEquals("200", call.getCode(), "验证code");
				verify();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExportSellerProductInfos_029() {
		Logger.start(true, "订单含有组合商品，分批导出卖家订单信息");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder10();

			Order order = placeOrderResp.getOrderList().get(0);

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			int sellerId = order.getSellerId();
			BigDecimal payAmount = placeOrderResp.getPayAmount();

			OrderCallService orderCallService = new OrderCallService();

			// 支付订单
			orderCallService.orderPayRequest(userId, payAmount, tradingId);

			SyncVerifyService.getSyncResult(order.getOrderId());

			request.setSellerId(sellerId);

			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-1,
					YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);

			call.setData(request);
			call.callService();

			Logger.verifyEquals("200", call.getCode(), "验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}